<template>
  <div class="app-container">
    <div class="handle-content">
      <el-input v-if="this.$store.getters.role.store_id == 0" v-model="storeId" placeholder="请输入店铺id" style="width: 200px;margin-right: 10px;">
        <el-button slot="append" @click="search">查询</el-button>
      </el-input>
    </div>
    <el-table v-loading="listLoading" :data="list" element-loading-text="拼命加载中" border fit highlight-current-row>
      <el-table-column v-if="this.$store.getters.role.store_id == 0" label="店铺ID" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.store_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="店铺总金额" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.total }}</span>
        </template>
      </el-table-column>
      <el-table-column label="店铺收入" align="center">
        <template slot-scope="scope">
          <span style="color: rgb(64, 158, 255);cursor:pointer;" @click="handle()">{{ scope.row.gold_sum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="虹包总金额" align="center">
        <template slot-scope="scope">
          <span style="color: rgb(64, 158, 255);cursor:pointer;" @click="exportExcel(1)">{{ scope.row.bonus_pool_one_sum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="报单奖励总金额" align="center">
        <template slot-scope="scope">
          <span style="color: rgb(64, 158, 255);cursor:pointer;" @click="exportExcel(2)">{{ scope.row.team_month_sum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="分虹总金额" align="center">
        <template slot-scope="scope">
          <span style="color: rgb(64, 158, 255);cursor:pointer;" @click="exportExcel(3)">{{ scope.row.team_year_sum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="招商奖励总金额" align="center">
        <template slot-scope="scope">
          <span style="color: rgb(64, 158, 255);cursor:pointer;" @click="exportExcel(4)">{{ scope.row.team_recommend_sum }}</span>
        </template>
      </el-table-column>
      <el-table-column label="教育培训基金总金额" align="center">
        <template slot-scope="scope">
          <span style="color: rgb(64, 158, 255);cursor:pointer;" @click="exportExcel(5)">{{ scope.row.team_fund_sum }}</span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="100">
        <template slot-scope="scope">
          <el-button @click="handleClick(scope.row.store_id)" type="primary" circle icon="el-icon-edit"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <gold-handle ref="goldHandle" @afterSave="afterSave" />
    <transfer-handle ref="transferHandle" @afterSave="afterSave" />
  </div>
</template>

<script>
/* eslint-disable */
import { goldSum } from '@/api/member'
import GoldHandle from './component/handle'
import TransferHandle from './component/transfer'
import { getToken } from '@/utils/auth' // get token from cookie

export default {
  components:{GoldHandle,TransferHandle},
  data() {
    return {
      list: [],
      listLoading: false,
      listQuery: {
        storeId: 0,
      },
      storeId: '',
      path: ''
    }
  },

  mounted() {
    this.getList()
  },

  methods: {
    getList() {
      this.listLoading = true
      goldSum(this.listQuery).then(response => {
        console.log(response)
        this.list = response.data.data
        this.path = response.data.path
        this.listLoading = false
      })
    },
    search() {
      this.listQuery.storeId = this.storeId
      console.log(this.storeId)
      console.log(this.listQuery)
      this.getList()
    },
    handle(){
      this.$refs.goldHandle.handle()
    },
    afterSave() {
      this.getList()
    },
    exportExcel(type) {
      const url = this.path + '?storeId=' + this.listQuery.storeId + '&type=' + type + '&token=' + getToken() + '&report=' + true

      location.href = url
    },
    handleClick(item){
      this.$refs.transferHandle.handle(item)
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.app-container{
    .handle-content{
        margin-bottom: 20px;
        .right{
            float: right;
        }
    }
}
</style>
<style>
.el-table .warning-row {
}

.el-table .success-row {
}
</style>
